package com.bumpslide.tween {
	
	import caurina.transitions.Tweener;
	import caurina.transitions.properties.DisplayShortcuts;	
	import flash.display.DisplayObject;	

	/**
	 * Tweener FadeIn/FadeOut shortcuts
	 * 
	 * These are the functions that were in BaseClip.
	 * They have been moved here to remove the dependencies on Tweener.
	 * 
	 * You may also be interested in the FTween.fadeIn and FTween.fadeOut 
	 * functions.  They have a slightly different syntax, but do about the 
	 * same thing and don't require Tweener.
	 * 
	 * @author David Knape
	 */
	public class Fade {
		
		private static var _initTweenerDisplayShortcuts:* = DisplayShortcuts.init();
		
		/**
		 *  fade in - with onComplete callback
		 */
		static public function fadeIn(target:DisplayObject, delay:Number=0, duration:Number=.4, onComplete:Function=null) : void {			
			Tweener.removeTweens(target, '_autoAlpha');
			if (target.alpha == 1 && target.visible) {
				if(onComplete!=null) onComplete.call(null); 
				return;
			}
			if(!target.visible) {
				target.visible = true; 
				target.alpha=0;
			}
			Tweener.addTween( target, { _autoAlpha:1, time:duration, transition:'easeOutQuad', delay:delay, onComplete:onComplete});            
		}
		
		/**
		 *  fade out - with onComplete callback
		 */
		public function fadeOut(target:DisplayObject, delay:Number=.1, duration:Number=.2, onComplete:Function=null) : void {
			Tweener.removeTweens(target, '_autoAlpha');
			if (!target.visible) { target.alpha = 0; if(onComplete!=null) onComplete.call(null); return; }
			Tweener.addTween( target, { _autoAlpha:0, time:duration, transition:'easeInQuad', delay:delay, onComplete:onComplete});        
		}
		
	}
}
